﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace ELTE.TFEG.ImageTransform.Hough
{
    public class HoughCircle : IComparable
    {
        public Point Center { get; set; }
        public int Radius { get; set; }
        public int Intensity { get; set; }
        public double RelativeIntensity { get; set; }

        public int CompareTo(object obj)
        {
            HoughCircle objAsCircle = obj as HoughCircle;
            if (objAsCircle == null)
            {
                return int.MinValue;
            }
            else
            {
                return (Intensity.CompareTo(objAsCircle.Intensity).Negate());
            }
        }

        public bool IntersectsOrContains(HoughCircle circle)
        {
            bool result = circle.Center.Distance(this.Center) < circle.Radius;
            return result;
        }

        public Bitmap TryDrawOnImage(Bitmap image, Pen pen)
        {
            try
            {
                
                using (Graphics g = Graphics.FromImage(image))
                {
                    Rectangle rect = new Rectangle(this.Center.X - this.Radius,this.Center.Y - this.Radius, 2 * this.Radius, 2 * this.Radius);
                    g.DrawEllipse(pen, rect);
                }
                return image;
            }
            catch (Exception ex)
            {
                return image;
            }
        }


    }
}
